
/******************************************************************************\
*       This is a part of the Microsoft Source Code Samples. 
*		  Copyright (C) 1994-1998 Microsoft Corporation.
*       All rights reserved. 
*       This source code is only intended as a supplement to 
*       Microsoft Development Tools and/or WinHelp documentation.
*       See these sources for detailed information regarding the 
*       Microsoft samples programs.
\******************************************************************************/

/*++

Copyright 1994 - 1998 Microsoft Corporation

Module Name:

    tlist.c

Abstract:

    This module implements a task list application.

--*/
#include "..\stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "..\resource.h"
//#include "..\MyTopDlg.h"

#define MAX_TASKS           256

#define PrintTask(idx) \
        printf( "%4d %-16s", tlist[idx].dwProcessId, tlist[idx].ProcessName ); \
        if (tlist[idx].hwnd) { \
            printf( "  %s", tlist[idx].WindowTitle ); \
        } \
        printf( "\n" );



DWORD numTasks;
TASK_LIST tlist[MAX_TASKS];
//VOID Usage(VOID);


int _cdecl
tlistmain(/*int argc,*/ char * pname)

/*++

Routine Description:

    Main entrypoint for the TLIST application.  This app prints
    a task list to stdout.  The task list include the process id,
    task name, ant the window title.

Arguments:

    argc             - argument count
    argv             - array of pointers to arguments

Return Value:

    0                - success

--*/

{
    DWORD             i;
    TASK_LIST_ENUM    te;
    BOOL              fTree;
    OSVERSIONINFO     verInfo = {0};
    LPGetTaskList     GetTaskList;
    LPEnableDebugPriv EnableDebugPriv;


    /*if (argc > 1 && (argv[1][0] == '-' || argv[1][0] == '/') && argv[1][1] == '?') {
        Usage();
    }*/

    //
    // Determine what system we're on and do the right thing
    //

    verInfo.dwOSVersionInfoSize = sizeof (verInfo);
    GetVersionEx(&verInfo);

    switch (verInfo.dwPlatformId)
    {
    case VER_PLATFORM_WIN32_NT:
       GetTaskList     = GetTaskListNT;
       EnableDebugPriv = EnableDebugPrivNT;
       break;

    case VER_PLATFORM_WIN32_WINDOWS:
       GetTaskList = GetTaskList95;
       EnableDebugPriv = EnableDebugPriv95;
       break;

    default:
       printf ("tlist requires Windows NT or Windows 95\n");
       return 1;
    }



    fTree = FALSE;

    //
    // Obtain the ability to manipulate other processes
    //
    EnableDebugPriv();

    memset(tlist,0,sizeof(tlist));
    //
    // get the task list for the system
    //
    numTasks = GetTaskList( tlist, MAX_TASKS );

    //
    // enumerate all windows and try to get the window
    // titles for each task
    //
    te.tlist = tlist;
    te.numtasks = numTasks;
    GetWindowTitles( &te );

    //
    // print the task list
    //
//    CMyTopDlg *dlg = (CMyTopDlg*)dlg->GetActiveWindow();
    for (i=0; i<numTasks; i++) 
    {
        CString pid,wind,num;
        num.Format("%03d",i+1);
        pid.Format("%d",tlist[i].dwProcessId);
        wind.Format("%d",tlist[i].hwnd);
  //      dlg->m_ProcessList.InsertItem(i,num);
    //    dlg->m_ProcessList.SetItemText(i,1,pid);
    //    dlg->m_ProcessList.SetItemText(i,2,wind);
     //   dlg->m_ProcessList.SetItemText(i,3,tlist[i].ProcessName);

        if (tlist[i].hwnd) 
        {
//            dlg->m_ProcessList.SetItemText(i,4,tlist[i].WindowTitle);
			true;
        } 
    }

    //
    // end of program
    //
    return 0;
}

/*VOID
Usage(
    VOID
    )
*/
/*++

Routine Description:

    Prints usage text for this tool.

Arguments:

    None.

Return Value:

    None.

--*/

/*{
    fprintf( stderr, "Microsoft (R) Windows NT (TM) Version 3.5 TLIST\n" );
    fprintf( stderr, "Copyright (C) 1994-1995 Microsoft Corp. All rights reserved\n\n" );
    fprintf( stderr, "usage: TLIST\n" );
    ExitProcess(0);
}
*/